web/src/pages/[...section].astro
376 lines · 9791 bytes
1---
2
3
4import Layout from '@layouts/Layout.astro';
5import Button from '@components/form/Button.astro';
6import Main from '@components/scafold/MainCard.astro';
7import ServiceList from '@components/things/ServiceList.astro';
8import type { AwesomePrivacy, Section, Service, ShortService } from '../types/Service';
9import { fetchData, slugify } from '@utils/fetch-data';
10import { parseMarkdown } from '@utils/parse-markdown';
11
12interface Props {
13 slug: string,
14 title: string,
15 services: Service[],
16 intro?: string,
17 notableMentions?: ShortService[] | string,
18 furtherInfo?: string,
19 wordOfWarning?: string,
20 alternativeTo?: string[];
21 categoryName: string,
22 otherSections: Section[],
23}
24
25const {
26 title, otherSections, services, notableMentions, furtherInfo, wordOfWarning,
27 alternativeTo, categoryName, intro,
28} = Astro.props;
29
30/**
31 * Make a list of keywords, for the <meta keywords> tag
32 */
33const makeKeyWordTag = () => {
34 const keywords = [];
35 keywords.push(`free and open source ${title} software`);
36 keywords.push(`private ${title} comparison`);
37 (alternativeTo || []).forEach((alt: string) => {
38 keywords.push(`privacy-respecting ${alt} alternative`);
39 keywords.push(`free open source ${alt} alternative`);
40 });
41 (services || []).forEach((serv: Service) => {
42 keywords.push(serv.name);
43 });
44 keywords.push('ad free');
45 keywords.push('open source software');
46 keywords.push('privacy respecting apps');
47 return keywords.join(', ');
48};
49
50/**
51 * Make a page title
52 */
53const makePageTitle = () => {
54 return `${title} | Awesome Privacy`;
55};
56
57const makeBreadcrumbs = () => {
58 return [
59 { name: 'Home', item: '/' },
60 { name: categoryName, item: slugify(categoryName) },
61 { name: title, item: `${slugify(categoryName)}/${slugify(title)}` },
62 ];
63};
64
65/**
66 * Make a string page intro, for the description tag
67 */
68const makeDescriptionTag = () => {
69 let description = `Privacy respecting ${title}. `;
70 if (services && services.length > 0) {
71 const serviceList = services.map((serv: Service) => serv.name);
72 description += `Compare ${serviceList.join(' vs ')} and more private, open source apps and services now. `
73 } else {
74 description += `Find private apps and services. This section is still a work in progress. `;
75 }
76 if (alternativeTo && alternativeTo.length > 0) {
77 description += `The best secure encrypted alternatives to ${alternativeTo.join(', ')} in 2024. `;
78 }
79 description += 'All this, and many more free and awesome tools and software.'
80 return description;
81};
82
83const makeCarasolData = () => {
84 return {
85 "@context": "https://schema.org",
86 "@type": "ItemList",
87 "itemListElement": [
88 services.map((service, index) => ({
89 "@type": "ListItem",
90 "position": index + 1,
91 "url": `https://awesomeprivacy.com/${slugify(categoryName)}/${slugify(title)}/${slugify(service.name)}`,
92 "item": {
93 "@type": "Service",
94 "name": service.name,
95 "description": service.description,
96 "image": service.icon,
97 "url": `https://awesomeprivacy.com/${slugify(categoryName)}/${slugify(title)}/${slugify(service.name)}`
98 }
99 })),
100 ]
101 }
102};
103
104export async function getStaticPaths() {
105 const pages = await fetchData().then((data) => {
106 const results: Array<Props> = [];
107 if (!data || !data.categories) return results;
108 (data as AwesomePrivacy).categories.forEach((category) => {
109 const sections = category.sections.map((section) => ({
110 slug: `${slugify(category.name)}/${slugify(section.name)}`,
111 title: section.name,
112 services: section.services,
113 intro: section.intro,
114 notableMentions: section.notableMentions,
115 furtherInfo: section.furtherInfo,
116 wordOfWarning: section.wordOfWarning,
117 alternativeTo: section.alternativeTo,
118 categoryName: category.name,
119 otherSections: category.sections,
120 }));
121 results.push(...sections);
122 });
123 return results;
124 });
125
126 return pages.map((props: Props) => {
127 return {params: { section: props.slug }, props };
128 });
129}
130
131const makePaginationLinks = () => {
132 const index = otherSections.findIndex(section => section.name === title);
133 const previousSection = index > 0 ? otherSections[index - 1].name : null;
134 const nextSection = index < otherSections.length - 1 ? otherSections[index + 1].name : null;
135 return { previous: previousSection, next: nextSection };
136};
137
138const { previous, next } = makePaginationLinks();
139
140---
141
142<Layout
143 title={makePageTitle()}
144 keywords={makeKeyWordTag()}
145 description={makeDescriptionTag()}
146 breadcrumbs={makeBreadcrumbs()}
147 customSchemaJson={makeCarasolData()}
148>
149 <Main>
150
151 <div class="breadcrumbs">
152 <span>
153 <a href="/">Awesome Privacy</a>
154 ➔ <a href={`/${slugify(categoryName)}`}>{categoryName}</a>
155 ➔ <a href={`/${slugify(categoryName)}/${slugify(title)}`}>{title}</a>
156 </span>
157 </div>
158
159 <h2>{title}</h2>
160
161 {intro && (
162 <section class="intro">
163 <p set:html={parseMarkdown(intro)}></p>
164 </section>
165 )}
166
167 <ServiceList services={services} sectionName={title} categoryName={categoryName} />
168
169 <details class="about-this-page">
170 <summary>Objective of this page</summary>
171 <p>
172 Find the best free, open source, E2E encrypted and private alternative to
173 {(alternativeTo || []).map((alt) => (<span>{alt}, </span>))} now.
174 </p>
175 <p>
176 Compare {(services || []).map((serv) => (<span>{serv.name} vs </span>))}
177 </p>
178 <p>
179 Discover the best {title} tools for Android, iPhone, Linux, PC and Chrome to download now.
180 And choose secure, self-hosted, peer-to-peer and independant alternatives in 2024
181 </p>
182 <p>
183 <b>Stop the invasion of privacy from big tech, improve data security stay safe.</b>
184 </p>
185 </details>
186
187
188 {notableMentions && (
189 <section class="notable-mentions">
190 <h3>Notable Mentions</h3>
191 { Array.isArray(notableMentions) ?
192 <ul>
193 {notableMentions.map((mention) => (
194 <li>
195 <a href={mention.url}>{mention.name}</a>
196 {mention.description && (
197 <span>- </span>
198 <span set:html={parseMarkdown(mention.description)}></span>
199 )}
200 </li>
201 ))}
202 </ul> :
203 <p set:html={parseMarkdown(notableMentions)}></p>
204 }
205 </section>
206 )}
207
208 {furtherInfo && (
209 <section class="further-info">
210 <h3>Notes</h3>
211 <p set:html={parseMarkdown(furtherInfo)}></p>
212 </section>
213 )}
214
215 {wordOfWarning && (
216 <section class="word-of-warning">
217 <h3>Word of Warning</h3>
218 <p set:html={parseMarkdown(wordOfWarning)}></p>
219 </section>
220 )}
221
222 {services.length > 0 && (<section class="submit-alternative">
223 <h3>Submit New Entry</h3>
224 <p>
225 Are we missing anything?
226 You can help us improve this page, by <a href="/submit">submitting a new entry</a>
227 </p>
228 </section>
229 )}
230
231 <div class="pagination-navigation">
232 { previous ? (
233 <Button url={`/${slugify(categoryName)}/${slugify(previous)}`}>
234 <span>← Previous</span>
235 <p>{previous}</p>
236 </Button>
237 ) : <p class="nothing"></p>}
238 <a href={`/${slugify(categoryName)}`} class="go-to-category">
239 View all in {categoryName} ({otherSections.length})
240 </a>
241 { next && (
242 <Button url={`/${slugify(categoryName)}/${slugify(next)}`}>
243 <span>Next →</span>
244 <p>{next}</p>
245 </Button>
246 )}
247 </div>
248 </Main>
249</Layout>
250
251<style lang="scss">
252
253section {
254 padding-bottom: 1rem;
255 &:not(:last-child) {
256 border-bottom: 2px solid var(--accent-3);
257 }
258}
259
260h2 {
261 font-size: 2rem;
262 margin: -2rem 0 2rem -2rem;
263 box-shadow: 6px 6px 0 var(--box-outline);
264 background: var(--accent);
265 color: var(--accent-fg);
266 width: fit-content;
267 padding: 0.25rem 0.5rem;
268 }
269
270.pagination-navigation {
271 display: flex;
272 justify-content: space-between;
273 align-items: center;
274 padding: 1rem 0;
275 :global(.button) {
276 min-width: 120px;
277 width: fit-content;
278 padding: 0.25rem 1rem;
279 text-align: right;
280 &:first-child { text-align: left; }
281 p {
282 margin: 0;
283 font-weight: normal;
284 font-size: 1rem;
285 }
286 span {
287 font-size: 0.8rem;
288 }
289
290 }
291 .nothing {
292 width: 120px;
293 }
294 .go-to-category {
295 color: var(--foreground);
296 font-size: 0.8rem;
297 opacity: 0.5;
298 @media (max-width: 768px) {
299 display: none;
300 }
301 }
302}
303
304.intro {
305 font-style: italic;
306 opacity: 0.7;
307}
308
309
310.further-info, .notable-mentions, .word-of-warning, .submit-alternative {
311 h3 {
312 font-size: 1.4rem;
313 margin: 1rem 0;
314 }
315 :global(p) {
316 font-size: 0.9rem;
317 opacity: 0.7;
318 :global(strong) {
319 font-weight: 500;
320 }
321 :global(a) {
322 color: var(--foreground);
323 transition: all 0.15s ease-in-out;
324 &:hover {
325 color: var(--accent);
326 }
327 }
328 }
329 :global(strong) {
330 font-weight: 500;
331 }
332 :global(h4) {
333 font-size: 1.2rem;
334 margin: 0.5rem 0 0 0;
335 }
336 :global(ul) {
337 list-style: circle;
338 padding-left: 1rem;
339 font-size: 0.9rem;
340 opacity: 0.7;
341 li {
342 margin-bottom: 0.25rem;
343 :global(p) {
344 display: inline;
345 }
346 }
347 }
348}
349.about-this-page {
350 summary {
351 display: none;
352 }
353 font-size: 0.9rem;
354 opacity: 0.7;
355}
356
357.breadcrumbs {
358 opacity: 0.5;
359 font-size: 0.8rem;
360 position: absolute;
361 right: 1rem;
362 top: 1rem;
363 a {
364 color: var(--foreground);
365 transition: all 0.15s ease-in-out;
366
367 &:hover {
368 color: var(--accent);
369 }
370 }
371 @media(max-width: 768px) {
372 display: none;
373 }
374}
375
376</style>